package com.coupon.bl;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Required;

import com.coupon.dal.entity.User;
import com.coupon.dao.impl.UserDaoImpl;


public class UserHandler  {
	private static final Logger LOG = Logger.getLogger(UserHandler.class.getName());

	private UserDaoImpl userDao;

	public UserHandler() {
		super();
	}
	
	@Required
	public void setUserDao(UserDaoImpl userDao) {
		this.userDao = userDao;
	}

	//@Transactional // not sure if needed ???
	public void addUser(User userEntity) throws CouponException{
		try{
			userDao.save(userEntity);
		}catch (Exception e) {
			LOG.info("PROBLEM = " + e.getMessage());
			 e.printStackTrace();
			throw new CouponException (Constant.USER_WITH_SAME_EMAIL_ALREADY_EXIST);
		}
	}
	 
	
	
	public void updateUser(User userEntity) throws CouponException{
		userDao.updateUser(userEntity);
	}
	
	public User findUser(String email) throws CouponException{
		return userDao.findbyPK(email);
	}
	
}
